ip and subnet check in python